﻿
namespace Sai.Core.Rules
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using Sai.Core.Introspection;

    public class AbstractClassMessageProvider : IMessageProvider
    {
        public AbstractClassMessageProvider(TypeName t)
        {
            this.TypeName = t;
        }

        private TypeName TypeName
        {
            get;
            set;
        }

        public string Message
        {
            get 
            {
                return string.Format("{0} is now abstract", this.TypeName.ToString());
            }
        }
    }

	/// <summary>
	/// Check for classes where they have been made abstract where previously not.
	/// </summary>
	public class CheckTypeAbstraction : IClassRule
	{
        public void Validate(ClassDeclaration was, ClassDeclaration isNow, ITypeDifference typeDifference)
		{
            if (!was.IsAbstract)
			{
				if (isNow.IsAbstract)
				{
					// type has been made abstract
					typeDifference.IdentifiedChange(
                        new UnaryTypeChange(
                            TypeChangeReason.TypeAbstract, 
                            isNow,
                            new AbstractClassMessageProvider(isNow.TypeName)
                            ));
				}
			}

		}
	}
}
